package com.ming.sorting.algorithm;

import java.util.Arrays;

/*
希尔排序
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] arr = new int[8000];

        for (int i = 0; i < 8000; i++) {
            arr[i] = (int) (Math.random() * 8000000);
        }
        long l = System.currentTimeMillis();
        shellSort(arr);
        long l1 = System.currentTimeMillis();
        System.out.println(l1 - l);
        System.out.println(Arrays.toString(arr));
    }

    public static void shellSort(int[] arr) {
        for (int gap = arr.length / 2; gap > 0; gap /= 2) {
            for (int i = gap; i < arr.length; i++) {
                int j = i;
                int temp = arr[j];
                while (j - gap >= 0 && temp < arr[j - gap]) {
                    arr[j]=arr[j-gap];
                    j -= gap;
                }
                arr[j]=temp;
            }
        }
    }
}
